<template>
  <div class="waitao">
    <div class="box">
      <h1>内部人员登录系统</h1>
      <el-form
        :model="user"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="账号" prop="username">
          <el-input v-model="user.userName"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input v-model="user.password"></el-input>
        </el-form-item>

        <el-form-item label="登录人员" prop="radio">
          <el-radio-group v-model="user.radio">
            <el-radio label="管理员"></el-radio>
            <el-radio label="销售员"></el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="login">立即登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import api from "../../network/apis/api";
export default {
  data() {
    return {
      user: {
        userName: "123",
        password: "123",
        radio: "管理员",
      },
    };
  },
  methods: {
    async login() {
      if (this.user.radio == "管理员") {
        const { data } = await api.admins.login(this.user);
        if (data.status) {
          this.$router.push("/admin");
          localStorage.token = data.token;
          localStorage.userName = data.loginer.userName;
          localStorage._id = data.loginer._id;
        } else {
          alert(data.message);
        }
      } else {
        //销售员的登录
        const { data } = await api.salesmans.login(this.user);
        if (data.status) {
          localStorage.token = data.token;
          localStorage.userName = data.loginer.userName;
          localStorage._id = data.loginer._id;
          this.$router.push("/salesman");
        }
      }
    },
  },
};
</script>

<style>
.box {
  width: 400px;
  height: 300px;
  margin: 100px auto;
}
.waitao {
  width: 600px;
  height: 300px;
  /* background: url('./img/abe1eea3ca79fc28-c577ebdcb0f3dbcc-aea9558e3eacd634f250d740f671de22.jpg'); */
  text-align: center;
  margin: 0px auto;
}
body {
  /* background: url('./img/timg.jpg') no-repeat ; */
  background-size: cover;
}
</style>
